package com.ilancuo.thinkinjava.chapter_15;

import java.util.Date;

interface TimeStamped {
    long getStamp();
}

class TimeStampedImpl implements TimeStamped {

    private final long timeStamp;

    public TimeStampedImpl() {
        timeStamp = new Date().getTime();
    }

    @Override
    public long getStamp() {
        return timeStamp;
    }
}

interface SerialNumbered {
    long getSerialNumber();
}

class SerialNumberedImpl implements SerialNumbered {

    private static long counter = 1;
    private final long serialNumber = counter++;

    @Override
    public long getSerialNumber() {
        return serialNumber;
    }
}

interface Basic {
    public void set(String val);

    public String get();
}

class BasicImpl implements Basic {

    private String value;

    @Override
    public void set(String val) {
        value = val;
    }

    @Override
    public String get() {
        return value;
    }
}

class MiXin extends BasicImpl implements TimeStamped, SerialNumbered {

    private TimeStamped timeStamp = new TimeStampedImpl();
    private SerialNumbered serialNumber = new SerialNumberedImpl();

    @Override
    public long getStamp() {
        return timeStamp.getStamp();
    }

    @Override
    public long getSerialNumber() {
        return serialNumber.getSerialNumber();
    }
}

public class MiXins {
    public static void main(String[] args) {
        MiXin miXin1 = new MiXin(), miXin2 = new MiXin();
        miXin1.set("test string 1");
        miXin2.set("test string 2");
        System.out.println(miXin1.get() + " " + miXin1.getStamp() + " " + miXin1.getSerialNumber());
        System.out.println(miXin2.get() + " " + miXin2.getStamp() + " " + miXin2.getSerialNumber());
    }
}
